package cn.zjj.controller;

import cn.zjj.domain.MovieTicket;
import cn.zjj.dto.UserTicketDto;
import cn.zjj.result.JsonResult;
import cn.zjj.service.IMovieTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movieticket")
public class MovieTicketController {
    @Autowired
    private IMovieTicketService movieTicketService;

    @GetMapping("/select")
    public JsonResult select(){
        List<MovieTicket> list=movieTicketService.select();
        return JsonResult.success(list);
    }

    @PostMapping("/selectUserTicket")
    public JsonResult selectUserTicket(@RequestBody UserTicketDto userTicketDto){
        MovieTicket movieTicket=movieTicketService.selectUserTicket(userTicketDto);
        return JsonResult.success(movieTicket);
    }

    @GetMapping("/selectById/{id}")
    public JsonResult selectById(@PathVariable("id") Long id){
        MovieTicket movieTicket=movieTicketService.selectById(id);
        return JsonResult.success(movieTicket);
    }

    @PostMapping("/buyTicket")
    public JsonResult buyTicket(@RequestBody UserTicketDto buyTicketDto){
        movieTicketService.buyTicket(buyTicketDto);
        return JsonResult.success();
    }

    @GetMapping("/getAllId")
    public JsonResult getAllId(){
         List<Long> list=movieTicketService.getAllId();
        return JsonResult.success(list);
    }
}
